##############################################################
#Figure D2: Distribution of Risk Aversion by Gender in HRS
##############################################################

data <- read.dta13("U:/temp/hrs_toplot.dta")
keepvars <- c("risk", "female")
data <- data[keepvars]
data <- na.omit(data)
data2 <- data %>%
  group_by(female, risk) %>%
  summarise(count=n()) %>%
  mutate(perc=count/sum(count))

data2$female2 <- factor(data2$female, levels = c(0,1), labels = c("Men", "Women"))

ggplot(data2, aes(as.factor(risk),y=perc,group=as.factor(female), fill=as.factor(female))) + 
  geom_bar(stat="identity", position = "dodge") + 
  scale_y_continuous(labels = percent) + 
  facet_grid(~female2) + ylab("Percent") + xlab("Risk Aversion") + 
  theme_bw() + 
  theme(panel.background = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.position = "none") + 
  scale_x_discrete(breaks=c(1,2,3,4,5,6), labels=c("Risk Taker", " ", " ", " ", " ", "Risk Averse")) + 
  scale_fill_manual(values=c("grey60", "grey60"))
ggsave("U:/export/figd2.pdf")
